package com.mtask.common.entity.task;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.mtask.common.entity.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.BatchSize;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "task_group")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class TaskGroup extends BaseEntity {
    private String groupName;

    @ManyToOne(fetch = FetchType.EAGER)
    @JsonBackReference
    @JoinColumn(
            name = "task_project_id",
            referencedColumnName = "id",
            nullable = false,
            columnDefinition = "integer")
    private TaskProject taskProject;


    @OneToMany(mappedBy = "taskGroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @OrderBy("id ASC")
    @BatchSize(size = 20)
    private Set<TaskJob> taskJobs = new HashSet<>();

    public TaskGroup(String name, TaskProject taskProject) {
        this.groupName = name;
        this.taskProject = taskProject;
    }
}
